package com.cn.txx.web.mq;

import java.io.IOException;
import java.util.ArrayList;

import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.MessageListener;
import javax.jms.TextMessage;

import org.springframework.web.socket.WebSocketSession;

import com.cn.txx.web.socket.MyWebSocketHandler;

public class MessageReceiver implements MessageListener{

	public void onMessage(Message message) {
		if (message instanceof TextMessage) {
            TextMessage textMessage = (TextMessage) message;
            try {
                String text = textMessage.getText();
                System.out.println("接收到消息: " + text);
                ArrayList<WebSocketSession> users = MyWebSocketHandler.users;
                for (WebSocketSession user : users) {
					user.sendMessage(new org.springframework.web.socket.TextMessage(text,true));
                }
            } catch (JMSException e) {
                e.printStackTrace();
            } catch (IOException e) {
				e.printStackTrace();
			}
        }
	}

}
